package com.huawei.classroom.student.h06;

public class Base{
	int hp,atp,x,y;
	double ar;
	public Base(int health,int attack,double ar,int x,int y) {
		this.hp=health;
		this.atp=attack;
		this.ar=ar;
		this.x=x;
		this.y=y;
	}
	
	public void move(int dx,int dy) {
		this.x+=dx;
		this.y+=dy;
	}
	public int getHealth() {
		if(this.hp<=0) return -1;
		return this.hp;
	}
	public boolean isDestroyed() {
		if(this.hp<=0) return true;
		return false;
	}
	
	public double getDistance(Base b) {
		return Math.sqrt((b.x-this.x)*(b.x-this.x)+(b.y-this.y)*(b.y-this.y));
	}
	
	public void attack(Soldier s) {
		if(ar<getDistance(s)) return ;
		if(s.hp>0) {
			s.hp-=this.atp;
			if(s.hp<=0) {
				Soldier.setDeadSoldier();
			}
		}
	}
	public void attack(Dog dog) {
		if(ar<getDistance(dog)) return ;
		if(dog.hp>0) {
			dog.hp-=this.atp;
		}
	}
	public void attack(Tank tank) {
		if(ar<getDistance(tank)) return ;
		if(tank.hp>0) {
			tank.hp-=this.atp;
		}
	}
	public void attack(Barrack b) {
		if(ar<getDistance(b)) return ;
		if(b.hp>0) {
			b.hp-=this.atp;
		}
	}
	public void attack(WarFactory w) {
		if(ar<getDistance(w)) return ;
		if(w.hp>0) {
			w.hp-=this.atp;
		}
	}
	
	
}